#
# Localized Starting Techs
# CvGreatGeneralsFromBarbarianCombatEventManager
# 

from CvPythonExtensions import *

import Popup as PyPopup

import CvUtil

import CvEventManager
import sys
import PyHelpers
import CvConfigParser
			
gc = CyGlobalContext()	

PyPlayer = PyHelpers.PyPlayer
PyGame = PyHelpers.PyGame()
localText = CyTranslator()

# Change the value to true if great generals should be allowed to be generated 
# through combat with barbarians.
# Default value is True
g_bEnableGreatGeneralsFromBarbarianCombat = True

# Change the value to true if great generals should be allowed to be generated 
# through combat with animals.
# Default value is True
g_bEnableGreatGeneralsFromAnimalCombat = True
							
# Change the value to true if great generals should be allowed for barbarians.
# Default Value is True
g_bEnableBarbarianGreatGenerals = True
							
# Set to true to print out debug messages in the logs
g_bDebug = false

LOG_ONLY = 1
SCREEN_ONLY = 2
LOG_AND_SCREEN = 3

# Change to redirect the debug messages to the logs, screen or both.
g_iDebugMessageTarget = LOG_ONLY


def loadConfigurationData():
	global g_bEnableGreatGeneralsFromBarbarianCombat
	global g_bEnableGreatGeneralsFromAnimalCombat
	global g_bEnableBarbarianGreatGenerals
	
	config = CvConfigParser.CvConfigParser("Great Generals From Barbarian Combat Mod Config.ini")

	if(config != None):

		g_bEnableGreatGeneralsFromBarbarianCombat = config.getboolean("Great Generals From Barbarian Combat Mod", "Enable Great Generals From Barbarian Combat", true)
		g_bEnableGreatGeneralsFromAnimalCombat = config.getboolean("Great Generals From Barbarian Combat Mod", "Enable Great Generals From Animal Combat", true)
		g_bEnableBarbarianGreatGenerals = config.getboolean("Great Generals From Barbarian Combat Mod", "Enable Barbarian Great Generals", true)

	gc.getGame().setGreatGeneralFromBarbarianCombat(g_bEnableGreatGeneralsFromBarbarianCombat)
	gc.getGame().setGreatGeneralFromAnimalCombat(g_bEnableGreatGeneralsFromAnimalCombat)
	gc.getGame().setBarbarianGreatGenerals(g_bEnableBarbarianGreatGenerals)
	
			
class CvGreatGeneralsFromBarbarianCombatEventManager:
	
	def __init__(self, eventManager):

		eventManager.addEventHandler("GameStart", self.onGameStart)
		eventManager.addEventHandler("windowActivation", self.onWindowActivation)
		#eventManager.addEventHandler("mouseEvent", self.onMouseEvent)

	def onMouseEvent(self, argsList):
		eventType,mx,my,px,py,interfaceConsumed,screens = argsList

		CyInterface().addImmediateMessage("%s %s %s %s" %(gc.getGame().isGreatGeneralFromBarbarianCombat(), gc.getGame().isBarbarianGreatGenerals(), gc.getPlayer(0).getCombatExperience(), gc.getPlayer(0).greatPeopleThreshold(true), ),"")

		objPlot = gc.getMap().plot(px,py)
		objUnit = objPlot.getUnit(0)

		if(objUnit != None):
			objUnit.setMoves(0)
			objUnit.setDamage(0, 0)

				

	def onWindowActivation(self, argsList):
		'Called when the game window activates or deactivates'
		bActive = argsList[0]
		if(bActive):
			loadConfigurationData()
				
	def onGameStart(self, argsList):
		loadConfigurationData()
		
